package com.spic.business.violation.supervision.speed.controller;

import com.spic.business.common.core.utils.poi.BusinessExcelUtil;
import com.spic.business.common.core.workflow.IWorkFlowService;
import com.spic.business.common.core.workflow.WorkFlowController;
import com.spic.business.hik.service.HkSafeService;
import com.spic.business.violation.supervision.speed.domain.ViolationsSpeedRecord;
import com.spic.business.violation.supervision.speed.service.IViolationsSpeedRecordService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

/**
 * 超速记录Controller
 *
 * @author yangjie
 * @date 2021-10-12
 */
@RestController
@RequestMapping("/violation/violations_speed_record")
public class ViolationsSpeedRecordController extends WorkFlowController
{
    @Autowired
    private IViolationsSpeedRecordService violationsSpeedRecordService;

    @Autowired
    private HkSafeService hkService;

    /**
     * 查询超速记录列表
     */
    //@PreAuthorize(hasPermi = "business/violation:violations_speed_record:list")
    @GetMapping("/list")
    public TableDataInfo list(ViolationsSpeedRecord violationsSpeedRecord)
    {

        startPage();
        List<ViolationsSpeedRecord> list = violationsSpeedRecordService.selectViolationsSpeedRecordList(violationsSpeedRecord);
        return getDataTable(list);
    }

    /**
     * 导出超速记录列表
     */
    @PreAuthorize(hasPermi = "business/violation:violations_speed_record:export")
    @Log(title = "超速记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ViolationsSpeedRecord violationsSpeedRecord) throws IOException
    {
        List<ViolationsSpeedRecord> list = violationsSpeedRecordService.selectViolationsSpeedRecordList(violationsSpeedRecord);
        ExcelUtil<ViolationsSpeedRecord> util = new BusinessExcelUtil<ViolationsSpeedRecord>(ViolationsSpeedRecord.class);
        util.exportExcel(response, list, "超速记录数据");
    }

    /**
     * 获取超速记录详细信息
     */
    @PreAuthorize(hasPermi = "business/violation:violations_speed_record:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(violationsSpeedRecordService.selectViolationsSpeedRecordById(id));
    }

    /**
     * 新增超速记录
     */
    @PreAuthorize(hasPermi = "business/violation:violations_speed_record:add")
    @Log(title = "超速记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ViolationsSpeedRecord violationsSpeedRecord)
    {
        return AjaxResult.success(violationsSpeedRecordService.insertViolationsSpeedRecord(violationsSpeedRecord));
    }

    /**
     * 修改超速记录
     */
    @PreAuthorize(hasPermi = "business/violation:violations_speed_record:edit")
    @Log(title = "超速记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ViolationsSpeedRecord violationsSpeedRecord)
    {
        return toAjax(violationsSpeedRecordService.updateViolationsSpeedRecord(violationsSpeedRecord));
    }

    /**
     * 删除超速记录
     */
    @PreAuthorize(hasPermi = "business/violation:violations_speed_record:remove")
    @Log(title = "超速记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(violationsSpeedRecordService.deleteViolationsSpeedRecordByIds(ids));
    }
    //可按照 违章来源、违章时间对违章数据进行统计
    @GetMapping("/getillegalSourcesByTime")
    public AjaxResult getillegalSourcesByTime(ViolationsSpeedRecord violationsSpeedRecord)
    {
        List<HashMap<String, Object>> stringObjectHashMap = violationsSpeedRecordService.getillegalSourcesByTime(violationsSpeedRecord);
        return AjaxResult.success(stringObjectHashMap);
    }

    //可按照 违章类型、违章时间对违章数据进行统计
    @GetMapping("/getiillegalTypeByTime")
    public AjaxResult getiillegalTypeByTime(ViolationsSpeedRecord violationsSpeedRecord)
    {
        List<HashMap<String, Object>> stringObjectHashMap = violationsSpeedRecordService.getiillegalTypeByTime(violationsSpeedRecord);
        return AjaxResult.success(stringObjectHashMap);
    }

    //可按照 违章区域、违章时间对违章数据进行统计
    @GetMapping("/getillegalAreaByTime")
    public AjaxResult getillegalAreaByTime(ViolationsSpeedRecord violationsSpeedRecord)
    {
        List<HashMap<String, Object>> stringObjectHashMap = violationsSpeedRecordService.getillegalAreaByTime(violationsSpeedRecord);
        return AjaxResult.success(stringObjectHashMap);
    }

    @Override
    protected IWorkFlowService getService()
    {
        return violationsSpeedRecordService;
    }


    /**
     * 车辆布控
     * @return
     */
    @GetMapping("/alarmCar/openOrClose")
    public AjaxResult doorOpenOrClose(){
        return violationsSpeedRecordService.doorOpenOrClose();
    }

    @GetMapping("filterDirtyData")
    public AjaxResult filterDirtyData() {
        violationsSpeedRecordService.filterDirtyData();
        return AjaxResult.success();
    }

}
